/*******************************************************************************
 * Copyright (c) 2012 Daniele Parisi.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Daniele Parisi
 *     neb.inf@gmail.com
 *     http://www.danieleparisi.com/
 ******************************************************************************/
package org.jxreport.html;

import org.jxreport.core.HTMLUtils;
import org.jxreport.core.Table;
import org.jxreport.core.views.twocols.TwoColsView;
import org.w3c.dom.Element;

public class HTMLTwoColsView extends TwoColsView implements HTMLView {

	public HTMLTwoColsView(Element textElement, Table table) {
		super(textElement, table);
	}

	@Override
	public String getJQueryCode() {
		String code = this.left.getJQueryCode();
		code += this.right.getJQueryCode();
		
		return code;
	}

	@Override
	public String getInnerDivCode() {

		String html = "";
		
		this.left.getCssProperties().put("float", "left");
		this.right.getCssProperties().put("float", "right");
		
		if(!this.left.getCssProperties().containsKey("width") && 
			!this.right.getCssProperties().containsKey("width") /*&&
			!this.left.getCssProperties().containsKey("padding") && 
			!this.right.getCssProperties().containsKey("padding")*/)
		{
			this.left.getCssProperties().put("width", "48%");
			//this.left.getCssProperties().put("padding", "15px");
			this.right.getCssProperties().put("width", "48%");
			//this.right.getCssProperties().put("padding", "15px");
		}
		
		String style = "style='";
		for (String cssProperty : this.left.getCssProperties().keySet())
			style += cssProperty + ": " + this.left.getCssProperties().get(cssProperty) + "; ";
		style += "' ";
		html += "<div id='" + this.left.getId() + "' " + style + ">";
		html +=  HTMLUtils.getDIVCode(this.left);
		html += "</div>";

		style = "style='";
		for (String cssProperty : this.right.getCssProperties().keySet())
			style += cssProperty + ": " + this.right.getCssProperties().get(cssProperty) + "; ";
		style += "' ";
		html += "<div id='" + this.right.getId() + "' " + style + ">";
		html +=  HTMLUtils.getDIVCode(this.right);
		html += "</div>";
		
		html += "<div style = 'clear:both'></div>";
		return html;
	}
}
